import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';

class ToastHelper {
  const ToastHelper._();

  static void loading() {
    BotToast.showCustomLoading(
      toastBuilder: (context) {
        return Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.transparent,
          child: const Center(
            child: CircularProgressIndicator(),
          ),
        );
      },
      allowClick: true,
      clickClose: true,
      crossPage: false,
    );
  }

  static void loadingUnClick() {
    BotToast.showCustomLoading(
      toastBuilder: (context) {
        return Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.transparent,
          child: const Center(
            child: CircularProgressIndicator(),
          ),
        );
      },
      allowClick: false,
      clickClose: false,
      crossPage: false,
    );
  }

  static void closeLoading() {
    BotToast.closeAllLoading();
  }

  static void show(String? text) {
    if (null == text) return;
    BotToast.showText(text: text);
  }

  static void showNotification(String? title, {String? subTitle}) {
    if (null == title) return;
    BotToast.showSimpleNotification(title: title, subTitle: subTitle);
  }

  ///[targetContext] 目标Widget(一般是一个按钮),使用上一般会使用[Builder]包裹,来获取到BuildContext
  ///[target] 目标[Offset],该偏移是以屏幕左上角为原点来计算的
  ///[target]和[targetContext] 只能二选一
  static void showAttachedWidget({required Widget child, int? seconds, BuildContext? targetContext, Offset? target}) {
    BotToast.showAttachedWidget(
      attachedBuilder: (_) => child,
      duration: Duration(seconds: seconds ?? 2),
      targetContext: targetContext,
      target: target,
    );
  }
}
